{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "gold_file = 'data/atis/test/label'\n",
    "predict_file = 'test_predictions.txt'\n",
    "text_file_en = 'data/atis/test/seq.in'\n",
    "text_file_vi = 'data/vi-atis/test/syllable/seq.in'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "intent_re = re.compile(r'<.*>')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "predicts = []\n",
    "with open(predict_file, 'r', encoding = 'utf-8') as f:\n",
    "    for line in f:\n",
    "        intent = intent_re.search(line).group(0)\n",
    "        intent = intent.replace('<', '')\n",
    "        intent = intent.replace('> ->', '')\n",
    "        predicts.append(intent)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "893"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(predicts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "golds = []\n",
    "with open(gold_file, 'r', encoding = 'utf-8') as f:\n",
    "    for line in f:\n",
    "        line = line.strip()\n",
    "        golds.append(line)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "out_file = 'compare_en_vi_intent.tsv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "text_en = open(text_file_en).readlines()\n",
    "text_vi = open(text_file_vi).readlines()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'i would like to find a flight from charlotte to las vegas that makes a stop in st. louis\\n'"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text_en[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "w = open(out_file, 'w', encoding = 'utf-8')\n",
    "headers = \"En\\tVi\\tGold\\tPredict\\n\"\n",
    "w.write(headers)\n",
    "for i,sample in enumerate(golds):\n",
    "    if sample != predicts[i]:\n",
    "        w.write(text_en[i].strip())\n",
    "        w.write('\\t')\n",
    "        w.write(text_vi[i].strip())\n",
    "        w.write('\\t')\n",
    "        w.write(sample)\n",
    "        w.write('\\t')\n",
    "        w.write(predicts[i])\n",
    "        w.write('\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
